package com.iolo.flinklog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iolo.flinklog.dao.TRelUserRoleDao;
import com.iolo.flinklog.dao.TUserDao;
import com.iolo.flinklog.entity.TRelUserRole;
import com.iolo.flinklog.entity.TUser;
import com.iolo.flinklog.entity.dto.UserDTO;
import com.iolo.flinklog.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户表 (TUser)表服务实现类
 *
 * @author fengxinxin
 * @since 2021-04-02 14:51:30
 */
@Service("tUserService")
public class TUserServiceImpl extends ServiceImpl<TUserDao, TUser> implements TUserService {
    @Autowired
    private TUserDao tUserDao;
    @Autowired
    private TRelUserRoleDao tRelUserRoleDao;
    @Override
    public int saveUserAndRole(UserDTO userDTO) {
        tUserDao.insert(userDTO);
        List<Long> roleIds = userDTO.getRoleIds();
        for (Long roleId : roleIds) {
            TRelUserRole tRelUserRole = new TRelUserRole();
            tRelUserRole.setRoleId(roleId);
            tRelUserRole.setUserId(userDTO.getUserId());
            tRelUserRoleDao.insert(tRelUserRole);
        }
        return 0;
    }
}
